from django.contrib import admin
from import_export.admin import ImportExportModelAdmin     # 实现导入导出功能模块
from apps.user.models import *
from apps.menu.models import *
from apps.order.models import *
from apps.goods.models import *
from apps.comment.models import *


# 商品表注册到后台
@admin.register(Goods)
class GoodsAdmin(ImportExportModelAdmin, admin.ModelAdmin):
    # 显示自定义的字段
    list_display = ['name', 'image', 'shop_name', 'find', 'type_id', 'create_time', 'show', 'p_price']
    # 自定义内容页中的字段
    # fields = ['name', 'image', 'shop_name', 'find', 'type_id', 'create_time', 'p_price']

    # 分组定义内容页中的内容
    fieldsets = (
        ('必填内容', {'fields': ['name', 'image',  'shop_name', 'find', 'type_id', 'create_time', 'p_price']}),
        ('选填内容', {
            'fields': ['target_url'],
            'classes': ('collapse',)
        })
    )
    # 搜索
    search_fields = ['name', 'type_id', ]
    ordering = ['id']
    # 每页显示的数据
    list_per_page = 10

    # 操作选项位置 使用了simpleui感觉不出来
    actions_on_top = False
    actions_on_bottom = True

    # 隐藏动作
    actions_show = False

    # 过滤器
    list_filter = ['find']

    # 添加显示字段点入内容框的字段
    list_display_links = ['name', 'image']


# 主菜单
@admin.register(MainMenu)
class MainMenuAdmin(admin.ModelAdmin):
    list_display = ['main_menu_id', 'main_menu_name']
    fields = ['main_menu_id', 'main_menu_name']
    ordering = ['main_menu_id']

    # 隐藏动作
    actions_show = False

    # 每页显示的数据
    list_per_page = 10


# 二级菜单
@admin.register(SubMenu)
class SubMenuAdmin(admin.ModelAdmin):
    list_display = ['show', 'sub_menu_type', 'sub_menu_name']
    fields = ['main_menu_id', 'sub_menu_id', 'sub_menu_type', 'sub_menu_name']
    ordering = ['sub_menu_id']

    # 隐藏动作
    actions_show = False

    # 每页显示的数据
    list_per_page = 10


@admin.register(Order)
class OrderAdmin(ImportExportModelAdmin, admin.ModelAdmin):
    list_display = ['trade_no', 'pay_status', 'mobile', 'order_amount']
    fields = ['trade_no', 'pay_status', 'ali_trade_no', 'is_delete', 'email', 'order_amount', 'pay_time', 'create_time']
    ordering = ['create_time']

    # 隐藏动作
    actions_show = False

    # 每页显示的数据
    list_per_page = 10


@admin.register(User)
class UserAdmin(ImportExportModelAdmin, admin.ModelAdmin):
    list_display = ['name', 'mobile', 'create_time']
    fields = ['name', 'mobile', 'birthday', 'gender', 'email', 'password', 'create_time']
    ordering = ['create_time']

    # 隐藏动作
    actions_show = False

    # 每页显示的数据
    list_per_page = 10


admin.site.site_header = '极客商城管理后台'  # 设置header
admin.site.site_title = '极客商城管理后台'  # 设置title
admin.site.index_title = '极客商城管理后台'



